<div class="layui-fluid layui-anim febs-anim" id="febs-teacherProject" lay-title="课程项目">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">

                    <form class="layui-form layui-table-form" enctype="multipart/form-data" id="user-add-form"  lay-filter="teacherProject-table-form">
                        <div class="layui-upload-drag" id="test10">
                            <i class="layui-icon"></i>
                            <p>点击上传，或将文件拖拽到此处</p>
                            <div class="layui-hide" id="uploadDemoView">
                                <hr>
                                <img src="" alt="上传成功后渲染" style="max-width: 196px">
                            </div>
                        </div>
                        <br/>
                        <span id="msg" style="color: red"></span>
                        <div style="width: 216px; margin: 0;">
                            <button type="button" id="sub" lay-submit="" lay-filter="user-add-form-submit"  class="layui-btn layui-btn-fluid">提交</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script data-th-inline="javascript">
    layui.use(['jquery', 'laydate', 'form', 'upload'], function () {
        var $ = layui.jquery,
            element = layui.element,
            form = layui.form,
            face = [[${face}]],
            $view = $('#febs-teacherProject'),
            upload = layui.upload;
        form.render();

        if (face === "1") {
            $("#msg").html("*您已进行人脸注册，如需重新录入请联系管理员")
            $("#sub").addClass("layui-btn-disabled").attr("disabled",true);
        }

        //拖拽上传
        upload.render({
            elem: '#test10',
            // url: ctx + 'scan/face/register', //改成您自己的上传接口
            accept: "images",
            acceptMime: 'image/*',//打开文件选择框时,只显示图片文件
            auto: false,  //是否选完文件后自动上传。默认值：true
            // bindAction: '#sub',
            choose: function (obj) {
                obj.preview(function (index, file, result) {
                    layui.$('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', result);
                })
            },
            done: function (res) {
                layer.msg('录入成功！', {
                    icon: 6,
                    time: 1000
                }, function () {
                    layer.closeAll();
                    window.location.reload();
                });
                console.log(res)
            }
        });

        form.on('submit(user-add-form-submit)', function (data) {
            var formData = new FormData(document.getElementById("user-add-form"));
            $.ajax({
                url: ctx + 'scan/face/register',
                data: formData,
                type: 'post',
                dataType: 'json',
                processData: false,
                contentType: false,
                success: function (data) {
                    if (data.code == 200) {
                        layer.msg(data.message, {
                            icon: 6,
                            time: 1000
                        }, function () {
                            layer.closeAll();
                            window.location.reload();
                        });
                    } else {
                        layer.msg('操作失败,请重新上传', {
                            icon: 5,
                            time: 1000
                        });
                    }
                },
                error: function (data) {
                    layer.msg('操作失败', {
                        icon: 5,
                        time: 1000
                    });
                }
            });

            /* febs.post(ctx + 'course/add', data.field, function () {
                 layer.closeAll();
                 $('#febs-user').find('#query').click();
             });*/
            return false;
        });

    })
</script>






